<template>
  <svg
    :class="svgClass"
    aria-hidden="true"
    :style="iconStyle"
    :title="title"
    @click="(e: Event) =>　emit('onClick', e)"
  >
    <use :xlink:href="iconName" />
  </svg>
</template>

<script lang="ts" setup>
import { computed } from 'vue'
type Props = {
  iconClass: string,
  title?: string,
  className?: string,
  size?: number,
}
const props = withDefaults(defineProps<Props>(), {
  title: '',
  className: '',
  size: 0
})

const iconStyle = computed(() => {
  if (props.size) {
    return { 'font-size': props.size + 'px' }
  }
  return {}
})

const iconName = computed(() => `#icon-${props.iconClass}`)

const svgClass = computed(() => props.className ? `'svg-icon ' + ${props.className}` : 'svg-icon')

const emit = defineEmits(['onClick'])
</script>

<style scoped>
  .svg-icon {
    width: 1em;
    height: 1em;
    vertical-align: -0.15em;
    fill: currentColor;
    overflow: hidden;
  }
</style>
